package self.rss.proto.util;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class DatabaseManager extends SQLiteOpenHelper {

	private static final String DB_NAME = "sjdroid.db";
	
	private static final int DB_VERSION = 2;
	
	public static final String INSERTTITEL = "INSERT INTO titel (titel, inhalt, link, datum) VALUES (?,?,?,?)";
	public static final String INSERTPODCAST = "INSERT INTO podcast (titel, inhalt, link, guid) VALUES (?,?,?,?)";
	public static final String INSERTTERMIN = "INSERT INTO termine (titel, inhalt, link, datum) VALUES (?,?,?,?)";
	
	
	private static final String Titel_CREATE =
		"CREATE TABLE titel (" +
		"_id INTEGER PRIMARY KEY AUTOINCREMENT," +
		"inhalt TEXT NOT NULL,"+
		"datum TEXT NOT NULL,"+
		"link TEXT NOT NULL,"+
		"titel TEXT NOT NULL"+ 
		")";
	
//	private static final String QUIZ_CREATE =
//		"CREATE TABLE quiz (" +
//		"_id INTEGER PRIMARY KEY AUTOINCREMENT," +
//		"frage TEXT NOT NULL,"+
//		"antwort1 TEXT NOT NULL,"+
//		"antwort2 TEXT NOT NULL,"+
//		"antwort3 TEXT NOT NULL,"+
//		"antwort4 TEXT NOT NULL,"+
//		"antwortmaster TEXT NOT NULL"+
//		")";
	
	private static final String Termine_CREATE =
		"CREATE TABLE termine (" +
		"_id INTEGER PRIMARY KEY AUTOINCREMENT," +
		"inhalt TEXT NOT NULL,"+
		"datum TEXT NOT NULL,"+
		"link TEXT NOT NULL,"+
		"titel TEXT NOT NULL"+ 
		")";
	
	private static final String Podcast_CEATE =
		"CREATE TABLE podcast (" +
		"_id INTEGER PRIMARY KEY AUTOINCREMENT," +
		"inhalt TEXT NOT NULL,"+
		"guid TEXT NOT NULL,"+
		"link TEXT NOT NULL,"+
		"titel TEXT NOT NULL"+ 
		")";

	private static final String TITEL_DROP = "DROP TABLE IF EXISTS titel";
	private static final String TERMINE_DROP = "DROP TABLE IF EXISTS termine";
	private static final String PODCASTS_DROP = "DROP TABLE IF EXISTS podcast";
	private static final String QUIZ_DROP = "DROP TABLE IF EXISTS quiz";
	
	
	public DatabaseManager(Context context) {
		super(context, DB_NAME, null, DB_VERSION);
	}

	
	@Override
	public void onCreate(SQLiteDatabase db) {
	
		db.execSQL(Titel_CREATE);
		db.execSQL(Termine_CREATE);
		db.execSQL(Podcast_CEATE);
//		db.execSQL(QUIZ_CREATE);
	}

	
	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
	
		db.execSQL(TITEL_DROP);
		db.execSQL(QUIZ_DROP);
		db.execSQL(TERMINE_DROP);
		db.execSQL(PODCASTS_DROP);
		onCreate(db);
	}
	
	public static int getDbVersion() {
		return DB_VERSION;
	}


	public void delete(SQLiteDatabase db){
		db.execSQL(TITEL_DROP);
		onCreate(db);
	}
	
	

}
